package jdk.functionclass;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

/**
 * @author songyafei
 */
public class BiFunctionFunction {
    public static void main(String[] args) {
        //BiFunction<T,U,R>
        //代表了一个接受两个输入参数的方法，并且返回一个结果
        BiFunction<Integer,Integer,Integer> biFunction = (b1,b2)-> b1 * b2;
        System.out.println(biFunction.apply(2,9));

        BiFunction<java.util.List<Integer>,java.util.List<Integer>,java.util.List<Integer>> listCal = (l1,l2)->{
            if(l1.size()<0||l2.size()<0){
                System.out.println("传入数据为空");
            }
            Map<Integer, Integer> collect = l1.stream().collect(Collectors.toMap(Integer::intValue, Integer::intValue, (t1, t2) -> t2));
            List<Integer> result = new ArrayList<>();
            l2.forEach(it->{
                Integer integer = collect.get(it);
                if(null!=integer){
                    result.add(it + integer);
                }
            });
            return result;
        };
        java.util.List<Integer> integers1 = Arrays.asList(1, 3, 14, 13, 19, 980);
        java.util.List<Integer> integers2 = Arrays.asList(3, 6, 25, 13, 16, 656);
        List<Integer> apply = listCal.apply(integers1, integers2);
        System.out.println(apply);
    }
}
